package com.plug.service;

import com.plug.entity.PlugContrast;
import com.plug.entity.PlugDatasource;
import com.plug.repository.PlugContrastMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 2016/12/19.
 */
@Service("plugContrastService")
public class PlugContrastServiceImpl implements IPlugContrastService {

    @Resource
    private PlugContrastMapper plugContrastMapper;

    /**
     * 根据目标数据源ID与源数据源ID查找备份记录
     * @param srcDsId 源数据源ID
     * @param tgtDsId 目标数据源ID
     * @return
     */
    public List<PlugContrast> findDataSourceID(Long srcDsId, Long tgtDsId) {
        return plugContrastMapper.findDataSourceID(srcDsId, tgtDsId);
    }

    /**
     * 根据数据库ID查询数据库是否被关联
     * @param dsId
     * @return
     */
    public int findContrastByDsID(Long dsId) {
        int result = plugContrastMapper.findContrastByDsID(dsId);
        if(result > 0){
            return 1;
        } else {
            return -1;
        }
    }

    public List<PlugContrast> findAll() {
        return plugContrastMapper.findAll();
    }

    /**
     * 根据数据源查询所有表格
     * @param srcDsId 源数据源ID
     * @return
     */
    public List<PlugContrast> findAllTable(Long srcDsId) {
        return plugContrastMapper.findAllTable(srcDsId);
    }

    @Override
    public List<Map<String, Object>> findDataSourceAndContrast() {
        return plugContrastMapper.findDataSourceAndContrast();
    }

    public PlugContrast findTgtTable(Long srcDsId,String srcDsTable, Long tgtDsId){
        return plugContrastMapper.findTgtTable(srcDsId,srcDsTable,tgtDsId);
    }

    public List<PlugContrast> findTaskAll() {
        return plugContrastMapper.findTaskAll();
    }

    /**
     * 根据任务ID查找任务
     * @param taskID
     * @return
     */
    public PlugContrast findTaskID(String taskID) {
        return plugContrastMapper.findTaskID(taskID);
    }

    @Override
    public PlugContrast findByID(Long id) {
        return plugContrastMapper.selectByPrimaryKey(id);
    }

    public PlugContrast findDatasourceByName( Long srcDsId,  Long tgtDsId,String srcTab){
        return plugContrastMapper.findDatasourceByName(srcDsId,tgtDsId,srcTab);
    }

    /**
     * 查询所有的 数据源信息
     * @return
     */
    public List<Map<String, Object>> dataSourecInfo(int pageIndex,int pageSize){
        return plugContrastMapper.dataSourecInfo( pageIndex, pageSize);
    }

    /**
     * 根据任务ID删除
     * @param plugContrastList
     * @return
     */
    public int deleteByPrimaryKey(List<PlugContrast> plugContrastList){
        return plugContrastMapper.deleteByPrimaryKey(plugContrastList);
    }
    /**
     * 新增数据配置信息
     * @param contrastList
     * @return
     */
    public int insert(PlugContrast contrastList){
        return plugContrastMapper.insert(contrastList);
    }
    /**
     * 修改单条记录
     * @param record
     * @return
     */
    public int updateByPrimaryKeySelective(PlugContrast record){
        return plugContrastMapper.updateByPrimaryKeySelective(record);
    }

    /**
     * 查询是否存在
     * @param record
     * @return
     */
    public Integer selectContrast(PlugContrast record){
        return plugContrastMapper.selectContrast(record);
    }
}

